package com.gwcloud.leetcode.tags.dp;

/** 
* @ClassName   : Leetcode0122 
* @author      : ganwei 
* @date        : 2020年5月17日 
* @Description : TODO 
*/
public class Leetcode0122 {
    /**
     * -动态规划
     */
	public int maxProfit(int[] prices) {
        int n = prices.length;
        int d_i_0 = 0;
        int d_i_1 = Integer.MIN_VALUE;
        for(int i = 0; i < n; i++) {
        	int temp = d_i_0;
        	d_i_0 = Math.max(d_i_0, d_i_1 + prices[i]);
        	d_i_1 = Math.max(d_i_1, temp - prices[i]);
        }
        
		return d_i_0;
    }
    /**
     * -主函数
     */
    public static void main(String[] args) {
    	int[] prices = {7,1,5,3,6,4};
    	Leetcode0122 l0122 = new Leetcode0122();
    	System.out.println(l0122.maxProfit(prices));
    }
}
